package com.jcbase.core.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.jcbase.model.SysConfigDatasource;

public class ConnUtil {


	    public static Connection getConn(String url ,String user,String password) 
	    { 
//	    	String url = "";
//	    	String user = "";		
//	    	String password = "";				
//	    			
//	    	SysConfigDatasource databases = SysConfigDatasource.dao.findById(1);
//	    	if(databases!=null){
//	    		url = databases.getHost();
//	    		user = databases.getUser();
//	    		password = databases.getDatabases();
//	    	}
	        Connection conn = null; 
	        try 
	        { 
	            Class.forName("org.postgresql.Driver"); 
	            String host = "jdbc:postgresql://"+url; 
	            try 
	            { 
	                conn = DriverManager.getConnection(host, user, password); 
	            } 
	            catch (SQLException e) 
	            { 
	                e.printStackTrace(); 
	            } 
	        } 
	        catch (ClassNotFoundException e) 
	        { 
	            e.printStackTrace(); 
	        } 
	 
	        return conn; 
	    } 
	 
	
    public static void main(String[] args) {
    	 Connection conn=ConnUtil.getConn("2","2","2"); 
         String sql="select * from student"; 
         Statement stmt=null; 
         ResultSet rs=null; 
         try 
         { 
             stmt=conn.createStatement(); 
             rs=stmt.executeQuery(sql); 
             while(rs.next()){ 
            	 String  view_name = rs.getString("view_name");
            	 String  workbooks_name = rs.getString("workbooks_name");
            	 String  project_name = rs.getString("project_name");
            	 String  view_url = rs.getString("view_url");
                 System.out.println(String.format("view_name : %s,workbooks_name %s：,project_name: %s,view_url : %s,", view_name,workbooks_name,project_name,view_url)); 
             } 
         } 
         catch (SQLException e) 
         { 
             e.printStackTrace(); 
         } 
     } 
    }
